Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
setsid();
+ if ((pid = fork()) > 0) {
+ exit(0);
+ } else if (pid == -1) {
+ err(errno, "fork() failed");
+ }
+
/* redirect fd 0,1,2 to /dev/null */
if ((fd = open("/dev/null",O_RDWR)) == -1) {
exit(1);
/* Session leader so ^C doesn't whack us. */
setsid();
+
+ /* Let session leader exit so child cannot regain CTTY */
+ if ((pid = fork()) < 0)
+ barf_perror("Failed to fork daemon");
+ if (pid != 0)
+ exit(0);
+
#ifndef TESTING /* Relative paths for socket names */
/* Move off any mount points we might be in. */
chdir("/");